package com.ithei.多线程第二天.原子性;

import java.util.concurrent.atomic.AtomicInteger;

public class Money {
    public static AtomicInteger money = new AtomicInteger(10000);
}

//CPU
class Demox1 extends Thread {
    @Override
    public void run() {

        while (Money.money.get() == 10000) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("money不是10000了...............");
    }
}

class Demox2 extends Thread {
    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Money.money.getAndSet(9000);

    }
}


class Testx1 {
    public static void main(String[] args) {
        Demox1 demox1 = new Demox1();
        Demox2 demox2 = new Demox2();
        demox1.start();
        demox2.start();
    }
}























